/**
 * 监听器
 * 
 */
class Listener {

    /**
     * 查看结果树
     * 
     * @param {XMLBuilder} parent 
     * @param {{testname: String, errorLogging: boolean, comments: String, filename: String}} config 
     * @returns
     */
    createViewResultsTree(parent, config = { testname: "View Results Tree", errorLogging: false, comments: "", filename: "" }) {
        const { testname, errorLogging, comments, filename } = config;
        const jmxViewResultsTree = parent.ele("ResultCollector", {
            guiclass: "ViewResultsFullVisualizer",
            testclass: "ResultCollector",
            testname: testname
        });
        jmxViewResultsTree.ele("boolProp", { name: "ResultCollector.error_logging" }).txt(errorLogging).up()
            .ele("objProp")
            .ele("name").txt("saveConfig").up()
            .ele("value", { class: "SampleSaveConfiguration" })
            .ele("time").txt("true").up()
            .ele("latency").txt("true").up()
            .ele("timestamp").txt("true").up()
            .ele("success").txt("false").up()
            .ele("label").txt("true").up()
            .ele("code").txt("true").up()
            .ele("message").txt("true").up()
            .ele("threadName").txt("true").up()
            .ele("dataType").txt("true").up()
            .ele("encoding").txt("false").up()
            .ele("assertions").txt("true").up()
            .ele("subresults").txt("true").up()
            .ele("responseData").txt("false").up()
            .ele("samplerData").txt("true").up()
            .ele("xml").txt("false").up()
            .ele("fieldNames").txt("true").up()
            .ele("responseHeaders").txt("false").up()
            .ele("requestHeaders").txt("false").up()
            .ele("responseDataOnError").txt("false").up()
            .ele("saveAssertionResultsFailureMessage").txt("true").up()
            .ele("assertionsResultsToSave").txt("0").up()
            .ele("bytes").txt("true").up()
            .ele("sentBytes").txt("true").up()
            .ele("url").txt("true").up()
            .ele("threadCounts").txt("true").up()
            .ele("idleTime").txt("true").up()
            .ele("connectTime").txt("true");
        jmxViewResultsTree.ele("stringProp", { name: "filename" }).txt(filename).up()
            .ele("stringProp", { name: "TestPlan.comments" }).txt(comments).up();
        jmxViewResultsTree.up().ele("hashTree");
    }

    /**
     * 聚合报告
     * 
     * @param {XMLBuilder} parent 
     * @param {{testname: String, comments: String, filename: String}} config 
     * @returns
     */
    createAggregateReport(parent, config = { testname: "Aggregate Report", comments: "", filename: "" }) {
        const { testname, comments, filename } = config;
        const jmxAggregateReport = parent.ele("ResultCollector", {
            guiclass: "StatVisualizer",
            testclass: "ResultCollector",
            testname: testname
        });
        jmxAggregateReport.ele("boolProp", { name: "ResultCollector.error_logging" }).txt("false").up()
            .ele("objProp")
            .ele("name").txt("saveConfig").up()
            .ele("value", { class: "SampleSaveConfiguration" })
            .ele("time").txt("true").up()
            .ele("latency").txt("true").up()
            .ele("timestamp").txt("true").up()
            .ele("success").txt("true").up()
            .ele("label").txt("true").up()
            .ele("code").txt("true").up()
            .ele("message").txt("true").up()
            .ele("threadName").txt("true").up()
            .ele("dataType").txt("true").up()
            .ele("encoding").txt("false").up()
            .ele("assertions").txt("true").up()
            .ele("subresults").txt("true").up()
            .ele("responseData").txt("false").up()
            .ele("samplerData").txt("true").up()
            .ele("xml").txt("false").up()
            .ele("fieldNames").txt("true").up()
            .ele("responseHeaders").txt("false").up()
            .ele("requestHeaders").txt("false").up()
            .ele("responseDataOnError").txt("false").up()
            .ele("saveAssertionResultsFailureMessage").txt("true").up()
            .ele("assertionsResultsToSave").txt("0").up()
            .ele("bytes").txt("true").up()
            .ele("sentBytes").txt("true").up()
            .ele("url").txt("true").up()
            .ele("threadCounts").txt("true").up()
            .ele("idleTime").txt("true").up()
            .ele("connectTime").txt("true");
        jmxAggregateReport.ele("stringProp", { name: "filename" }).txt(filename).up()
            .ele("stringProp", { name: "TestPlan.comments" }).txt(comments).up();
        jmxAggregateReport.up().ele("hashTree");
    }

}

module.exports = Listener;

